package com.kystar.muxplayer;


import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ToggleButton;

import android.widget.TextView;
import com.kystar.muxplayer.manager.PresetLayoutManager;
import com.kystar.muxplayer.manager.PvmManager;
import com.kystar.muxplayer.manager.SettingsViewManager;
import com.kystar.muxplayer.manager.ThreeBottomManager;
import com.kystar.muxplayer.manager.WindowsManager;
import com.kystar.muxplayer.selfview.MyConstraintLayout;
import com.kystar.muxplayer.selfview.PvmFrameLayout;
import com.kystar.muxplayer.ui.ButtonSetting;
import com.kystar.muxplayer.ui.HeadButtonSetting;
import com.kystar.muxplayer.ui.SourceSetting;


public class MainActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Window _window = getWindow();
        WindowManager.LayoutParams params = _window.getAttributes();
        params.systemUiVisibility =
                View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE;
        _window.setAttributes(params);


        setContentView(R.layout.activity_loading);
        BaseApp.loadAll().subscribe(settings -> {
        }, e -> {
            e.printStackTrace();
            ((TextView)findViewById(R.id.text)).setText("Error:"+e.getMessage());
        }, this::init);


    }

    private void init() {
        setContentView(R.layout.activity_main);

        new SourceSetting(this, findViewById(R.id.source));

        FrameLayout presetLayout = findViewById(R.id.presetLayout);
        PresetLayoutManager presetLayoutManager = PresetLayoutManager.getPresetSingleInstance();
        presetLayoutManager.init(presetLayout);

        MyConstraintLayout conStraintLayout = findViewById(R.id.myConStraintLayout);
        LinearLayout rightParent = findViewById(R.id.layout_right_parent);
        LinearLayout settingGroup = rightParent.findViewById(R.id.settings_group);
        // SettingGroupManager settingGroupManager = new SettingGroupManager(getApplicationContext(),settingGroup,conStraintLayout);
        SettingsViewManager settingsViewManager = new SettingsViewManager(settingGroup,conStraintLayout);

        PvmFrameLayout frameLayout = findViewById(R.id.frame1);

        RecyclerView recyclerView = rightParent.findViewById(R.id.recycleView);
        WindowsManager windowsManager = WindowsManager.getInstance();
        windowsManager.initView(recyclerView,frameLayout);

        PvmManager pvmManager = PvmManager.getPvmSingleInstance();
        pvmManager.init(frameLayout);

        new ButtonSetting(getApplicationContext(), findViewById(R.id.main_pvw_toolbar));
        new HeadButtonSetting(getApplicationContext(), findViewById(R.id.layout_top));

        ToggleButton posLock = rightParent.findViewById(R.id.pvw_position_lock);
        ToggleButton showInfo = rightParent.findViewById(R.id.pvw_layer_info_on);
        View savePresets = rightParent.findViewById(R.id.pvw_save_settings_dumpy);
        ThreeBottomManager threeBottomManager = ThreeBottomManager.getInstance();
        threeBottomManager.initView(posLock,showInfo,savePresets);
    }

    @Override
    public void onBackPressed() {
        //不能返回
    }
}
